package cn.tedu.lucky.draw.user.handler;

import cn.tedu.lucky.draw.user.protocol.po.UserLog;
import cn.tedu.lucky.draw.user.service.IUserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;

@Component
public class UserLogHandler {
    /**
     * ServerRequest代表HTTP请求，包含对请求头和请求体的访问
     * ServerResponse代表HTTP响应，包含对请求头和请求体的访问
     */
    @Autowired
    private IUserLogService userLogService;

    public Mono<ServerResponse> findAll(ServerRequest request){
        Flux<UserLog> userLogFlux = userLogService.findAll();
        return ServerResponse.ok().body(fromPublisher(userLogFlux,UserLog.class));
    }
}
